

ARM_SRCS := atexit_arm.cc eh_arm.cc
SUP_SRCS := \
  array_type_info.cc \
  atexit_thread.cc \
  bad_alloc.cc \
  bad_cast.cc \
  bad_typeid.cc \
  class_type_info.cc \
  del_op.cc \
  del_opnt.cc \
  del_opv.cc \
  del_opvnt.cc \
  dyncast.cc \
  eh_alloc.cc \
  eh_aux_runtime.cc \
  eh_call.cc \
  eh_catch.cc \
  eh_exception.cc \
  eh_globals.cc \
  eh_personality.cc \
  eh_ptr.cc \
  eh_term_handler.cc \
  eh_terminate.cc \
  eh_throw.cc \
  eh_tm.cc \
  eh_type.cc \
  eh_unex_handler.cc \
  enum_type_info.cc \
  function_type_info.cc \
  fundamental_type_info.cc \
  guard.cc \
  guard_error.cc \
  hash_bytes.cc \
  nested_exception.cc \
  new_handler.cc \
  new_op.cc \
  new_opnt.cc \
  new_opv.cc \
  new_opvnt.cc \
  pbase_type_info.cc \
  pmem_type_info.cc \
  pointer_type_info.cc \
  pure.cc \
  si_class_type_info.cc \
  tinfo.cc \
  tinfo2.cc \
  vec.cc \
  vmi_class_type_info.cc \
  vterminate.cc

C11_SRCS = \
  chrono.cc \
  compatibility-atomic-c++0x.cc \
  compatibility-c++0x.cc \
  compatibility-chrono.cc \
  compatibility-thread-c++0x.cc \
  condition_variable.cc \
  debug.cc \
  fstream-inst.cc \
  functexcept.cc \
  functional.cc \
  future.cc \
  hash_c++0x.cc \
  hashtable_c++0x.cc \
  limits.cc \
  mutex.cc \
  placeholders.cc \
  random.cc \
  regex.cc \
  shared_ptr.cc \
  string-inst.cc \
  system_error.cc \
  thread.cc \
  wstring-inst.cc

C98_SRCS = \
  allocator-inst.cc \
  bitmap_allocator.cc \
  codecvt.cc \
  compatibility-debug_list-2.cc \
  compatibility-debug_list.cc \
  compatibility.cc \
  complex_io.cc \
  concept-inst.cc \
  ctype.cc \
  ext-inst.cc \
  globals_io.cc \
  hash_tr1.cc \
  hashtable_tr1.cc \
  ios-inst.cc \
  ios.cc \
  ios_failure.cc \
  ios_init.cc \
  ios_locale.cc \
  iostream-inst.cc \
  istream-inst.cc \
  istream.cc \
  list-aux-2.cc \
  list-aux.cc \
  list.cc \
  list_associated-2.cc \
  list_associated.cc \
  locale-inst.cc \
  locale.cc \
  locale_facets.cc \
  locale_init.cc \
  localename.cc \
  math_stubs_float.cc \
  math_stubs_long_double.cc \
  misc-inst.cc \
  mt_allocator.cc \
  ostream-inst.cc \
  parallel_settings.cc \
  pool_allocator.cc \
  sstream-inst.cc \
  stdexcept.cc \
  streambuf-inst.cc \
  streambuf.cc \
  strstream.cc \
  tree.cc \
  valarray.cc \
  wlocale-inst.cc

SYM_SRCS = \
  atomicity.cc \
  basic_file.cc \
  c++locale.cc \
  codecvt_members.cc \
  collate_members.cc \
  ctype_configure_char.cc \
  ctype_members.cc \
  messages_members.cc \
  monetary_members.cc \
  numeric_members.cc \
  time_members.cc

ARM_SYMS_PATH:=$(INS_ROOT)/../../../gcc_libs_arm_work/arm-nacl/libstdc++-v3/src/c++98

LIBCPP_FLAGS := -gdwarf-3 -DANDROID
LIBCPP_FLAGS += -I$(SRC_ROOT)/../../gcc_libs/libgcc -I$(SRC_ROOT)/../../gcc/include
LIBCPP_FLAGS += -DIN_LIBGCC2
LIBCPP_FLAGS += -fno-implicit-templates -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi
LIBCPP_FLAGS += -fdiagnostics-show-location=once -ffunction-sections -fdata-sections
LIBCPP_FLAGS += -I$(SRC_ROOT)/../../gcc_libs/libstdc++-v3/libsupc++
LIBCPP_FLAGS += -U_GLIBCXX_HAVE_IEEEFP_H
LIBCPP_FLAGS += -I$(SRC_ROOT)/../../gcc_libs/libstdc++-v3/libsupc++
LIBCPP_FLAGS += -g -O0

ifeq ($(NACL_ARCH),arm)
ARCH_FLAGS:=$(ARM_FLAGS)
ARCH_OBJS := $(subst .cc,.o,$(ARM_SRCS))
ARCH_SRCS := $(ARM_SRCS)
else
ARCH_FLAGS:=
ARCH_OBJS :=
ARCH_SRCS :=
endif

SUP_OBJS := $(subst .cc,.o,$(SUP_SRCS)) cp-demangle.o
C11_OBJS := $(subst .cc,.o,$(C11_SRCS))
C98_OBJS := $(subst .cc,.o,$(C98_SRCS))
SYM_OBJS := $(subst .cc,.o,$(SYM_SRCS))

LIBIBERTY_ROOT := $(SRC_ROOT)/../../gcc/libiberty
GCC_SRC_ROOT := $(SRC_ROOT)/../../gcc_libs/libstdc++-v3

$(eval $(call BASIC_COMPILE_TARGET,cp-demangle.o,$(LIBIBERTY_ROOT)/cp-demangle.c,$(CC),$(LIBCPP_FLAGS)))

$(foreach src,$(ARCH_SRCS) $(SUP_SRCS),$(eval $(call BASIC_COMPILE_TARGET,$(basename $(src)).o,$(GCC_SRC_ROOT)/libsupc++/$(src),$(CXX),$(LIBCPP_FLAGS))))
$(foreach src,$(C11_SRCS),$(eval $(call BASIC_COMPILE_TARGET,$(basename $(src)).o,$(GCC_SRC_ROOT)/src/c++11/$(src),$(CXX),$(LIBCPP_FLAGS) -std=gnu++11)))
$(foreach src,$(C98_SRCS),$(eval $(call BASIC_COMPILE_TARGET,$(basename $(src)).o,$(GCC_SRC_ROOT)/src/c++98/$(src),$(CXX),$(LIBCPP_FLAGS))))
$(foreach src,$(SYM_SRCS),$(eval $(call BASIC_COMPILE_TARGET,$(basename $(src)).o,$(ARM_SYMS_PATH)/$(src),$(CXX),$(LIBCPP_FLAGS))))

$(eval $(call BASIC_LIB_TARGET,$(INS_ROOT)/libsupc++.a,$(ARCH_OBJS) $(SUP_OBJS),$(AR)))
$(eval $(call BASIC_LIB_TARGET,$(INS_ROOT)/libstdc++.a,$(ARCH_OBJS) $(SUP_OBJS) $(C11_OBJS) $(C98_OBJS) $(SYM_OBJS),$(AR)))
